package com.site.wisdom_construction.controller.scheduleModule;

import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.service.scheduleModule.DelayRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/1/12
 * @Description
 */
@Api(tags = "延期记录信息接口")
@RestController
@RequestMapping("DelayRecord")
@CrossOrigin
public class DelayRecordController {
    @Autowired
    private DelayRecordService delayRecordService;

    @ApiOperation(value = "增加延期记录信息", notes = "测试数据:")
    @PostMapping("/insertDelayRecord")
    public JsonResult insertDelayRecord(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = delayRecordService.insertDelayRecord(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功录入延期记录信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("录入延期记录信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "删除延期记录信息信息", notes = "测试数据:")
    @PostMapping("/deleteDelayRecord")
    public JsonResult deleteDelayRecord(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        List<Integer> list = (List<Integer>) map.get("list");
        int l = 0;
        Map mapR = new HashMap();
        for (int i = 0;i<list.size();i++){
            mapR.put("id",list.get(i));
            int a = delayRecordService.deleteDelayRecord(mapR);
            l+=a;
        }
        if (l>=1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功删除延期记录信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除延期记录信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "修改延期记录信息", notes = "测试数据:")
    @PostMapping("/updateDelayRecord")
    public JsonResult updateDelayRecord(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = delayRecordService.updateDelayRecord(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功修改延期记录信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("修改延期记录信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "分页模糊查询延期记录信息", notes = "测试数据:")
    @PostMapping("/findDelayRecordByPage")
    public Page findDelayRecordByPage(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(delayRecordService.Total(map));
        page.setItems(delayRecordService.findDelayRecordByPage(map));
        return page;
    }
}
